package com.xmy.cultivate.mapper;

import com.xmy.cultivate.entity.MqSchedulingLog;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 上课提醒与扣课时 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2024-06-12
 */
public interface MqSchedulingLogMapper extends BaseMapper<MqSchedulingLog> {

    @Select({"<script>",
            "SELECT",
                      "t.* ",
                    "FROM",
                      "(",
                      "SELECT",
                        "id,",
                        "school_date,",
                        "start_date_time,",
                        "end_date_time,",
                        "`status`,",
                        "1 AS `scheduling_type` ",
                      "FROM",
                        "course_scheduling_detail ",
                      "WHERE",
                        "year_part = ${yearPart} ",
                        "AND `quarter` = ${quarterNum} ",
                        "AND school_date = '${schoolDate}' ",
                        "<when test='lessonType!=null and lessonType!=&apos;&apos;'>",
                            "AND lesson_type = ${lessonType}",
                        "</when>",
                        "AND `status` &lt;&gt; 2 ",
                        "AND deleted = 0 UNION ALL",
                      "SELECT",
                        "id,",
                        "school_date,",
                        "start_date_time,",
                        "end_date_time,",
                        "`status`,",
                        "2 AS `scheduling_type` ",
                      "FROM",
                        "repair_course ",
                      "WHERE",
                        "year_part = ${yearPart} ",
                        "AND `quarter` = ${quarterNum} ",
                        "AND school_date = '${schoolDate}' ",
                        "<when test='lessonType!=null and lessonType!=&apos;&apos;'>",
                            "AND lesson_type = ${lessonType}",
                        "</when>",
                        "AND `status` &lt;&gt; 2 ",
                        "AND deleted = 0 ",
                      ") AS t",
                      "LEFT JOIN mq_scheduling_log AS t_mq ON t.id = t_mq.id ",
                      "AND t_mq.`status` &lt;&gt; 0 ",
                    "WHERE",
                      "t_mq.id IS NULL ",
                      "OR ( t.start_date_time &lt;&gt; t_mq.start_date_time OR t.end_date_time &lt;&gt; t_mq.end_date_time ) ",
                    "ORDER BY",
                      "t.start_date_time ASC;",
            "</script>"})
    public abstract List<MqSchedulingLog> getSchedulingList(@Param("yearPart") Integer yearPart,
                                                        @Param("quarterNum") Integer quarterNum,
                                                        @Param("schoolDate") String schoolDate,
                                                        @Param("startDateTime") String startDateTime,
                                                        @Param("endDateTime") String endDateTime,
                                                        @Param("lessonType") String lessonType);
}
